package main

import (
	"jtdevice/api"
	"jtdevice/app"
	"jtdevice/configs"
	"jtdevice/pkg/svc"
	"log"
	"os"
)

func main() {
	if err := configs.Load("config.yaml"); err != nil {
		log.Fatal(err)
	}
	svc.Run(&svc.Program{
		AppName: func() string {
			if len(os.Args) > 2 {
				configs.AppName = os.Args[2]
			}
			return configs.AppName
		},
		Description: "jtdevice service application",
		Run: func() error {
			if err := app.Run(); err != nil {
				return err
			}
			return api.Run()
		},
		Shutdown: func() error {
			api.Shutdown()
			return app.Shutdown()
		},
	})
}
